package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.NewsAuthDto;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
@Api(value = "自媒体和管理端文章相关接口", tags = "自媒体和管理端文章相关接口")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询文章
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("自媒体端查询所有内容列表")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findAll(dto);
    }

    /**
     * 发布修改文章或保存为草稿
     *
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("自媒体端发布修改文章或保存为草稿")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) {
        return wmNewsService.submitNews(dto);
    }

    /**
     * 查看文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    @ApiOperation("自媒体端查看文章详情")
    public ResponseResult findOne(@PathVariable Integer id) {
        return wmNewsService.findOne(id);
    }

    /**
     * 文章删除
     *
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    @ApiOperation("自媒体端文章删除")
    public ResponseResult delNews(@PathVariable Integer id) {
        return wmNewsService.delNews(id);
    }


    @PostMapping("/down_or_up")
    @ApiOperation("自媒体端文章上下架")
    public ResponseResult downOrUpNews(@RequestBody WmNewsDto dto) {

        return wmNewsService.downOrUpNews(dto);
    }
//TODO -------------------------------------------------------------------------admin端相关接口

    @PostMapping("/list_vo")
    @ApiOperation("管理端文章列表分页查询")
    public ResponseResult listByPage(@RequestBody NewsAuthDto dto){return wmNewsService.listByPage(dto);
    }

    @GetMapping("/one_vo/{id}")
    @ApiOperation("管理端查询文章详情")
    public ResponseResult getOneInAdmin(@PathVariable Integer id){
        return wmNewsService.getOneInAdmin(id);
    }

    @PostMapping("/auth_fail")
    @ApiOperation("管理端文章审核失败")
    public ResponseResult fail(@RequestBody NewsAuthDto dto){
        return wmNewsService.fail(dto);
    }

    @PostMapping("/auth_pass")
    @ApiOperation("管理端文章审核成功")
    public ResponseResult pass(@RequestBody NewsAuthDto dto){
        return wmNewsService.pass(dto);
    }

}